package com.yzwu.lambda;

/**
 * @author yzwu
 * @date 2022/5/28 9:21
 * 基于狂神初探lambda、推导lamda表达式
 */
public class Lambada0 {
    //2、静态内部类
    static class Like2 implements ILike{
        @Override
        public void lambda() {
            System.out.println("I like Lambda2!");
        }
    }
    public static void main(String[] args) {
        ILike like = new Like();
        like.lambda();

        like = new Like2();
        like.lambda();

        //3、局部内部类
        class Like3 implements ILike{
            @Override
            public void lambda() {
                System.out.println("I like Lambda3!");
            }
        }
        like = new Like3();
        like.lambda();

        //4、匿名内部类 没有类的名称 必须借助接口或者父类 直接new接口进行重写
        like = new ILike() {
            @Override
            public void lambda() {
                System.out.println("I like Lambda4!");
            }
        };
        like.lambda();
        //5、用lambda简化。类和方法名都不要，直接括号开始+方法体。
        like = ()->{
            System.out.println("I like Lambda5!");
        };
        like.lambda();
    }

}
//0、定义一个函数式接口
interface ILike{
    void lambda();
}
//1、实现类
class Like implements ILike{
    @Override
    public void lambda() {
        System.out.println("I like Lambda1!");
    }
}